package com.yanqu.road.dao.impl.log;

import com.alibaba.fastjson.JSONArray;
import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.*;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Author cwq
 * @Data 2022/1/4 17:50
 */
public class LogLogShuiHuYeZiCardDaoImpl extends TempDao {

    public boolean addLogShuiHuYeZiCardBattlerResultRecordList(List<LogShuiHuYeZiCardBattlerResultRecord> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_shuihuyezicard_battle_result_record(activityId,userId,type,roomId,isWin,targetId,oldRankScore,newRankScore,reward,startTime,time) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogShuiHuYeZiCardBattlerResultRecord data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getType()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getRoomId()));
            para.put(i++, new DbParameter(Types.BOOLEAN, data.isWin()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTargetId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getOldRankScore()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getNewRankScore()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getReward()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getStartTime()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }


    public boolean addLogShuiHuYeZiCardGetCardList(List<LogShuiHuYeZiCardGetCard> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_shuihuyezicard_get_record(activityId,userId,type,cardId,oldCardLevel,oldQuality,newCardLevel,newQuality,num,integral,time) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogShuiHuYeZiCardGetCard data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getType()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCardId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOldCardLevel()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOldQuality()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getNewCardLevel()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getNewQuality()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getNum()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getIntegral()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }


    public boolean addLogShuiHuYeZiCardPVEBattlerRoundRecordList(List<LogShuiHuYeZiCardPVEBattlerRoundRecord> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_shuihuyezicard_pve_battle_round_record(activityId,roomId,startTime,userId,userCardList,playCardId,aiId,npcUserCardList,npcPlayCardId,buffId,winnerId,time) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogShuiHuYeZiCardPVEBattlerRoundRecord data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getRoomId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getStartTime()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.VARCHAR, JSONArray.toJSONString(data.getUserCardList())));
            para.put(i++, new DbParameter(Types.INTEGER, data.getPlayCardId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getAiId()));
            para.put(i++, new DbParameter(Types.VARCHAR, JSONArray.toJSONString(data.getNpcUserCardList())));
            para.put(i++, new DbParameter(Types.INTEGER, data.getNpcPlayCardId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getBuffId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getWinnerId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogShuiHuYeZiCardPVPBattlerRoundRecordList(List<LogShuiHuYeZiCardPVPBattlerRoundRecord> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getCrossDb());
        String sql = "INSERT INTO t_c_activity_shuihuyezicard_pvp_battle_round_record(startTime,userMap,playCardRecordList,winnerId,endTime) VALUES(?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogShuiHuYeZiCardPVPBattlerRoundRecord data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getStartTime()));
            para.put(i++, new DbParameter(Types.VARCHAR, JSONArray.toJSONString(data.getUserMap())));
            para.put(i++, new DbParameter(Types.VARCHAR, JSONArray.toJSONString(data.getPlayCardRecordList())));
            para.put(i++, new DbParameter(Types.BIGINT, data.getWinnerId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getEndTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogShuiHuYeZiCardPVPMatchRecordList(List<LogShuiHuYeZiCardPVPMatchRecord> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getCrossDb());
        String sql = "INSERT INTO t_c_activity_shuihuyezicard_pvp_match_record(activityId1,playerId1,rankScore1,playerId2,rankScore2,startMatchTime,time) VALUES(?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogShuiHuYeZiCardPVPMatchRecord data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId1()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getPlayerId1()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getRankScore1()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getPlayerId2()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getRankScore2()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getStartMatchTime()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

}
